package com.yiqi.liebang.feature.setting.view.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.RatingBar;
import com.yiqi.liebang.entity.bo.QuestionBo;

import java.util.List;
import java.util.Vector;

public class PrivacyAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private int lastPosition = -1;                                //记录上一次选中的图片位置，-1表示未选中
    private Vector<Boolean> vector = new Vector<Boolean>();

    public PrivacyAdapter(List<String> baseBos) {
        super(R.layout.item_private, baseBos);
        for (int i = 0; i < baseBos.size(); i++) {
            vector.add(false);
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        helper.setText(R.id.tv_user_money, item + "");

        ImageView bt_room_press = helper.getView(R.id.iv_private_sign);
        if (vector.elementAt(helper.getPosition()) == true) {
            bt_room_press.setBackground(AM.app().getResources().getDrawable(R.drawable.icon_yanzheng));

        } else {
            bt_room_press.setBackground(AM.app().getResources().getDrawable(R.drawable.list_btn_meixuanzhong));

        }

    }


    public void changeState(int position) {
        if (lastPosition != -1)
            vector.setElementAt(false, lastPosition);                   //取消上一次的选中状态
        vector.setElementAt(!vector.elementAt(position), position);     //直接取反即可
        lastPosition = position;                                        //记录本次选中的位置
        notifyDataSetChanged();                                         //通知适配器进行更新
    }

    public void changeNull() {
        for (int i = 0; i < vector.size(); i++) {
            vector.setElementAt(false, i);
        }
    }
}